<template>
	<div style="position:relative;">
		<div v-for="(x,y) in item" >
			<div class="two" style="overflow: hidden;background:white;">
				<div class="contest" >
					<ul class="left" @click="goBussiness(x.shopInfo.id)" :id="x.shopInfo.id">
						<li class="text"><img :src="x.shopInfo.logo" style="margin-right: .1rem;width:.6rem;height:.6rem;border-radius:50%;margin-right:.1rem;">{{x.shopInfo.name}}<img src="https://khh-server.oss-cn-beijing.aliyuncs.com/resourse/IMG/static/more@2x.png" style="width: 0.14rem;height: 0.26rem;margin-left: .12rem;"></li>
					</ul>
					<ul class="right">
						<li class="success">{{x.byType.msg}}</li>
					</ul>
				</div>
				<div class="cutDetail" @click="goOrderdetails($event)" :orderid="x.orderid">
					<ul class="photo">
						<li><img :src="x.proInfo.thumb"></li>
					</ul>
					<ul class="cut-right">
						<li class="one" style="-webkit-box-orient: vertical;">{{x.proInfo.title}}</li>
						<li class="twos">{{x.proInfo.spec}}<span>X{{x.proInfo.buyNum}}</span></li>
						<li class="three">
							<span class="icon" >¥</span>
							<span class="money">{{x.proInfo.minPrice}}</span>&nbsp;&nbsp;
							<span class="before" style="text-decoration: line-through; font-size:.24rem; color:#969696">¥{{x.proInfo.maxPrice}}</span>
						</li>
					</ul>     
				</div>
				<div class="cut-btn">
					<p class="allMoney">共<span>1</span>件商品 总价 :  <span style="font-weight: bold;font-size:.24rem;">¥{{x.proInfo.minPrice}}</span>(包邮)</p >
					<div class="btn">
						<button v-for="(z,y) in x.byType.btType" ref="payBtn" :type="z.type"  @click="toPayState($event)" :keys="z.key" :orderid="x.orderid">{{z.key | status}}</button>
					</div>
				</div>
			</div>
			<div style="background:#f6f6f6;height:.2rem;width:100%;"></div>
		</div>
		<v-alert :context="context" v-if="showAlert"></v-alert>
	</div>
</template>

<script>
	import Button from "./button.vue";
    import config from "../config/config.js";
    import store from "../store/newStore.js";
    import Alert from "../alert.vue";
	export default{
        data(){
            return{
                opaText:false,
                shsh:false,
                contentText:'',
                btnType:'',
                orderId:'',
                textNobtn:'',
				height:'',
                btType:'',
                context:'',
                showAlert:false
            }
        },
		components:{
			"v-button":Button,
            "v-alert":Alert
		},
		props:{
			item:Object
		},
        filters:{
			status:function(val){
				switch(val){
					case 'CANCEL_ORDER':
						return "取消订单";
					case 'PAY_ORDER':
						return "付款";
					case 'URGE_ORDER':
						return "催发货";
					case 'EXTEND_ORDER':
						return "延长收货";
					case 'SHOW_LOGISTICS':
						return "查看物流";
					case 'SURE_ORDER':
						return "确认收货";
					case 'DELETE_ORDER':
						return "删除订单";
					case 'AFTER_BUY':
						return "申请售后";
					case 'REMARK_ORDER':
						return "评价";
					case 'UPDATE_REFUND':
						return "修改申请";
                    case 'CANCEL_REFUND':
                        return "撤销申请";
                    case 'APPLY_PLATFORM_IN':
                        return "申请砍好货介入";
                    case 'AGAIN_REFUND':
                        return "重新申请";
                    case 'UPDATE_REMARK':
                        return "追评";
                    case 'FAX_LOGISTICS':
                        return "填写退货物流";
					case 'SHOW_DETAILS':
					    return '查看详情';
                }
			}
		},
		methods:{
            toPayState($event){
                var e=$event.currentTarget,
					keys=e.getAttribute('keys'),
                    orderid=e.getAttribute('orderid');
                this.btnType=keys;
                this.orderId=orderid;
                if(keys=='SHOW_DETAILS'){
                    this.$router.push('/threekan/'+orderid)
				}
				if(keys=='SHOW_LOGISTICS'){
					this.goLogistics(orderid,keys)
				}
				if(keys=='DELETE_ORDER'){
                    this.$store.commit('orderStatus',{"contentText":'确定要删除订单吗?',"textNobtn":"删除成功",'orderid':orderid,"type":keys});
					this.$parent.$parent.showToast();
				}
				if(keys=='EXTEND_ORDER'){
                    this.contentText='<p>确认延长收货时间？</p><p>每笔订单只能<span>延长一次</span>哦</p>';
                    this.$parent.$parent.showPop();
                    this.opaText=true;
				}
				if(keys=='REMARK_ORDER'){
                    var shopImg=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getElementsByClassName('photo')[0].getElementsByTagName('img')[0].getAttribute('src'),
                        orderid=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getAttribute('orderid'),
						title=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getElementsByClassName('cut-right')[0].getElementsByTagName('li')[0].innerHTML;
                    this.goAssess(shopImg,orderid)
				}
				if(keys=='URGE_ORDER'){
                    this.urgeOrder(orderid,keys)
				}
				if(keys=='SURE_ORDER'){
                    this.$store.commit('orderStatus',{"contentText":'确认收货吗?',"textNobtn":"确认收货成功",'orderid':orderid,"type":keys});
                    this.$parent.$parent.showToast();
				}
				if(keys=='UPDATE_REMARK'){
                    var shopImg=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getElementsByClassName('photo')[0].getElementsByTagName('img')[0].getAttribute('src'),
                        orderid=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getAttribute('orderid'),
                        title=e.parentNode.parentNode.parentNode.getElementsByClassName('cutDetail')[0].getElementsByClassName('cut-right')[0].getElementsByTagName('li')[0].innerHTML;
                        this.updateRemark(shopImg,orderid,title)
				}
				if(keys=='CANCEL_ORDER'){
                    this.$store.commit('orderStatus',{"contentText":'确定取消该订单吗?',"textNobtn":"取消成功",'orderid':orderid,"type":keys});
                    this.$parent.$parent.showToast();
				}
				if(keys=='PAY_ORDER'){
                    var money=e.parentNode.parentNode.parentNode.getElementsByClassName('money')[0].innerHTML;
                    this.$parent.$parent.payOrder(1,money,orderid)
				}
			},
            goBussiness(id){
              this.$router.push('/business/'+id)
			},
			goOrderdetails($event){
                var e=$event.currentTarget,
                    orderid=e.getAttribute('orderid'),
					type=sessionStorage.getItem("index");
                switch(type){
                    case '0':
                        type='A';
                        break;
                    case '1':
                        type='C';
                        break;
                    case '2':
                        type='D';
                        break;
                    case '3':
                        type='E';
                        break;
                    case '4':
                        type='F';
                        break;
                }
                this.$router.push('/orderdetail/'+orderid+'/'+type)
			},
			goLogistics(orderid,bt_type){
                this.$router.push('/logistics/'+orderid+'/'+bt_type);
			},
			extendOredr(orderid,bt_type){
                var value=JSON.stringify({"orderid":orderid,"bt_type":bt_type,"token":localStorage.getItem('token')}),
                    key=demo(value);
                axios.post('/Home/order/OrderButtonListener',{
                        value:value,
                        key:key
                },config)
                    .then(function(response) {
                        if(response.data.code==200){
                            var type=sessionStorage.getItem("index");
                            var that=this;
                            switch(type){
                                case '0':
                                    type='A';
                                    break;
                                case '1':
                                    type='C';
                                    break;
                                case '2':
                                    type='D';
                                    break;
                                case '3':
                                    type='E';
                                    break;
                                case '4':
                                    type='F';
                                    break;
                            }
                            this.opaText=false;
                            this.$parent.$parent.showPop();
                            this.shsh=true;
                            this.textNobtn='延长收货成功';
                            setTimeout(function(){
                                that.$parent.$parent.hidePop();
                                that.shsh=false;
                                that.$parent.$parent.checkOrder(type)
                            },1000)
                        }
                    }.bind(this))
                    .catch(function (error) {
                        console.log(error);
                    });
			},
            urgeOrder(orderid,bt_type){
                var value=JSON.stringify({"orderid":orderid,"bt_type":bt_type,"token":localStorage.getItem('token')}),
                    key=demo(value);
                axios.post('/Home/order/OrderButtonListener',{
                        value:value,
                        key:key
                },config)
                    .then(function(response) {
                        if(response.data.code==200){

                        }
                    }.bind(this))
                    .catch(function (error) {
                        console.log(error);
                    });
			},
			goAssess(imgUrl,orderid,){
				this.$router.push({
					path:'/assess',
					query:{
					    imgUrl:imgUrl,
                        orderid:orderid
					}
				})
			},
            updateRemark(imgUrl,orderid){
                this.$router.push({
                    path:'/addTo',
                    query:{
                        imgUrl:imgUrl,
                        orderid:orderid
                    }
                })
			},
            opDelete(){
                    this.$parent.$parent.hidePop();
                    this.opaText = false,
                    this.shsh = false
            }
		},
		mounted(){
            console.log(this.$store)
		}
	}
</script>

<style>
</style>